function alg=rac(alg)

global NUMBER_OF_EVENTS LENGTH BIG TNOW MAINT_COST REPAIR_COST SALES_REVENUE EXP_RATE 
global SHAPE1 SCALE1 SHAPE2 SCALE2 SHAPE3 SCALE3 B U L MU STATES_MAX NET_ITERMAX ISTAR

alg.iter=alg.iter+1;

a = alg.old_action;
% in the following 1 is added because in MATLAB index of an array starts
% from 1
i1 = alg.old_prodcount+1;
j1 = alg.prodcount+1;

rimm=alg.revenue;
timm=TNOW-alg.time;


%beta=15000/(30000+alg.iter); % Works for smaller cases
% gather the value of the Q-factor to be updated
beta=100/(500+alg.iter);

%beta=10/(300+(3*alg.iter));

%beta =log(alg.iter+2)/(alg.iter+2);
alpha=15000/(30000+alg.iter);
Jold=alg.J(i1);
Piold=alg.Pi(i1,a);




Jnext=alg.J(j1);
Jstar=alg.J(ISTAR);


  

  % update the Pi
  
Pinew=((1-alpha)*Piold) +(alpha*(rimm-(Jstar*timm)+Jnext));
Jnew=((1-beta)*Jold)+(beta*(rimm-(Jstar*timm)+Jnext));
alg.Pi(i1,a)=Pinew;
alg.J(i1)=Jnew;



alg.revenue=0;
alg.time=TNOW;





